package com.gy.smart.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gy.smart.R;
import com.gy.smart.home.bean.HelpHomeBean;
import com.gy.smart.util.ListViewItemListener;

import java.util.List;

/**
 * 作者：gy on 16/11/3
 * 说明：黄页列表adapter
 */
public class HelpHomeAdapter extends BaseAdapter {

    private Context context;
    private List<HelpHomeBean> list;
    private ListViewItemListener listener;

    public HelpHomeAdapter(Context context, List<HelpHomeBean> list){
        this.context = context;
        this.list = list;
    }

    public void setListener(ListViewItemListener listener){
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view == null){
            view = View.inflate(context, R.layout.adapter_help_home,null);
            holder = new ViewHolder();
            holder.tvName = (TextView) view.findViewById(R.id.adapter_help_home_tv_name);
            holder.tvAddress = (TextView) view.findViewById(R.id.adapter_help_home_tv_address);
            holder.imgMap = (ImageView) view.findViewById(R.id.adapter_help_home_img_map);
            holder.imgPhone = (ImageView) view.findViewById(R.id.adapter_help_home_img_phone);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tvName.setText(list.get(position).mechanism_name+"");
        holder.tvAddress.setText(list.get(position).address+"");

        holder.imgMap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null){
                    listener.doPassActionListener(null,0,position,"");
                }
            }
        });

        holder.imgPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener != null){
                    listener.doPassActionListener(null,1,position,"");
                }
            }
        });

        return view;
    }

    class ViewHolder{
        TextView tvName,tvAddress;
        ImageView imgMap,imgPhone;
    }
}
